package com.mc.bintree;

/**
 * @Description: 并查集
 * @Author: MoChen
 */
public class UnionFind {

    static final int MAX_SIZE = 10;
    int fa[] = new int[MAX_SIZE];

    /**
     * 初始化
     */
    void initial(int n){
        for(int i = 1; i <= n; ++i){
            fa[i] = i;
        }
    }

    /**
     * 查询
     */
    int find(int x){
        return x == fa[x] ? x : (fa[x] = find(fa[x]));
    }

    /**
     * 合并
     */
    void merge(int i, int j){
        fa[find(i)] = find(j);
    }

}
